package cc.ding.dao.Impl;

import cc.ding.dao.BaseDao;
import cc.ding.dao.EmployeeDao;
import cc.ding.entity.Employee;

import java.sql.ResultSet;
import java.sql.SQLException;

public class EmployeeDaoImpl extends BaseDao implements EmployeeDao {
    @Override
    public Employee login(String employeeNo, String password) {
        //sql指令
        String sql = "select * from employee where employeeNo = ? AND `password` = ? and dimission = 1";

        ResultSet resultSet = executeQuery(sql, employeeNo, password);
        if (resultSet!=null){
            try {
                while (resultSet.next()){
                    Employee employee = new Employee();
                    employee.setId(resultSet.getInt("id"));
                    employee.setEmployeeNo(resultSet.getString("employeeNo"));
                    employee.setName(resultSet.getString("name"));
                    employee.setImgPath(resultSet.getString("imgPath"));
                    employee.setSex(resultSet.getString("sex"));
                    employee.setBirthday(resultSet.getDate("birthday"));
                    employee.setDepId(resultSet.getInt("depId"));
                    employee.setPositionId(resultSet.getInt("positionId"));
                    employee.setPhone(resultSet.getString("phone"));
                    employee.setEntryDate(resultSet.getDate("entryDate"));
                    employee.setEmail(resultSet.getString("email"));
                    employee.setDimission(resultSet.getInt("dimission"));

                    return employee;
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                closedAll(resultSet);
            }
        }

        return null;
    }
}
